<template>
  <main class="supplier-system">
    <div class="mini-n-width system" v-if="!url">
      <p class="content">{{content}}</p>
    </div>
    <div class="mini-n-width system" v-else>
      <pdf :src="url" v-for="i in numPages" :key="i" :page="i" class="pdf-class"></pdf>
      <div class="supplier-footer min">
          <a-button @click="goBack" class="s-btn">
            返回
          </a-button>
        </div>
    </div>
  </main>
</template>
<script>
import pdf from 'vue-pdf'
export default {
  data () {
    return {
      currentIndex: 0,
      url: '',
      content: '',
      numPages: null,
      form: this.$form.createForm(this)
    }
  },
  components: {
    pdf
  },
  computed: {
  },
  created () {
    this.CYPY_KJCXJ_PXFF()
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    },
    CYPY_KJCXJ_PXFF () {
      this.$http.CYPY_KJCXJ_PXFF({}).then(res => {
        if (res.data && res.data.list && res.data.list.length && res.data.list[0].realPath) {
          this.url = `${process.env.VUE_APP_SRC}${res.data.list[0].realPath}`
          this.getNumPages()
        } else {
          this.content = res.data.list[0].content
        }
      })
    },
    getNumPages () {
      let loadingTask = pdf.createLoadingTask(this.url)
      loadingTask.promise.then(pdf => {
        this.numPages = pdf.numPages
      }).catch(err => {
        console.error('pdf 加载失败', err)
      })
    },
    goNext () {
      this.$http.validToken({}).then(res => {
        if (!res.data) {
          this.$router.push({ path: '/login', query: { back: window.location.href } })
        } else {
          this.$router.push({ path: `/innovation/supplier/1` })
        }
      })
    },
    handleSubmit (e) {
    },
    resetForm () {
      this.form.resetFields()
    }
  }
}
</script>
<style lang="scss">
</style>
